# 读取成绩文件实现排序
# coding = utf-8

# 读取文件，去除换行符，然后拼到一个列表里
def open_file(file_name):
    result = []
    with open(file_name, 'r', encoding='utf-8') as f:
        for line in f:
            line = line[:-1]
            print(line)
            result.append(line.split(","))
    return result


# 排序
def sort_data(datas):
    # return sorted(datas, key=lambda x: int(x[0].split(',')[-1]), reverse=True)
    return sorted(datas, key=lambda x: int(x[2]), reverse=True)


def write_data(datas):
    with open("012write.txt", 'w', encoding='utf-8') as f:
        for data in datas:
            print(data)
            f.write(",".join(data) + "\n")


file_path = "012.txt"
a = open_file(file_path)
print(a)
print(type(a))
b = sort_data(a)
print(b)
write_data(b)
